<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>任务执行情况</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        $(document).ready(function() {
            $("#btnExport").click(function(){
                top.$.jBox.confirm("确认要导出用户数据吗？","系统提示",function(v,h,f){
                    if(v=="ok"){
                        $("#searchForm").attr("action","${ctx}/sys/user/export");
                        $("#searchForm").submit();
                    }
                },{buttonsFocus:1});
                top.$('.jbox-body .jbox-icon').css('top','55px');
            });
            $("#btnImport").click(function(){
                $.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},
                    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
            });
        });
		$(document).ready(function() {

		});

        function exportData() {
            var taskMainId = $("#taskMainId").val();
            window.location.href="${ctx}/devmng/taskMain/exportData?taskMainId=" + taskMainId;
        }

		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }

        function wrapTable(attaVo) {
			if (!attaVo) {
			    return "<table><tr><td>没有内容</td></tr></table>";
			}
			var content = "<table style=\"width: 80%\">";
			content += wrapTr4Img(attaVo.title, attaVo.urlList);
			content += "</table>";
			return content;
		}

		function wrapTr4Img(title, urlList) {
			var content = "<tr>"
			content += wrapTd(title);
			content += wrapTd4ImgList(urlList);
			content += "</tr>";
			return content;
		}

		function wrapTd(content) {
		    return "<td>" + content + "</td>";
		}

		function wrapTd4ImgList(urlList) {
		    if (!urlList || urlList.length == 0) {
		        return "<td></td>";
			}
			var content = "<td>";
			for (var i = 0; i < urlList.length; i++) {
				content += wrapImg(urlList[i]);
			}
			content += "</td>";
			return content;
		}

		function wrapImg(url) {
		    return "<img width=\"200\" height=\"200\" src=\"" + url + "\" />";
		}

        function showDetail(taskMainId, deviceMainId, devchkItemId) {

            var url = "${ctx}/devmng/taskMain/getTaskDetail";
            var params = {
                taskMainId: taskMainId,
                deviceMainId: deviceMainId,
                devchkItemId: devchkItemId
            };
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(params),
                contentType: 'application/json;charset=utf-8',
                success: function(data) {
                    var height = $(window).height()-200;
                    var width = $(document.body).width()-100;
                    var title = "详情";

                    if (!data || !data.taskDetailAttaVo) {
                        $.jBox.open("没有任何内容", title, width, height);
                        return;
					}
                    var content = wrapTable(data.taskDetailAttaVo);
                    $.jBox.open(content, title, width, height);
                },
                fail: function(err, status) {
                    console.log(err)
                }
            });
		}
	</script>
	<style>
		#bc-close td  {
			color: #3fa43f;
		}
		#bc-open td  {
			color: #ff0100;
		}
		#bc-processing td  {
			color: #042aa1;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="#">任务执行情况列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="taskMainExecDetialRequest" action="${ctx}/devmng/taskMain/taskMainExecDetailListSingle" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
				<%--<li><label>计划开始：</label>
                    <input name="beginTaskStart" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
                        value="<fmt:formatDate value="${taskMainExecDetialRequest.beginTaskStart}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                        onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> -
                    <input name="endTaskStart" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
                        value="<fmt:formatDate value="${taskMainExecDetialRequest.endTaskStart}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                        onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
                </li>
                <li><label>计划结束：</label>
                    <input name="beginTaskEnd" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
                        value="<fmt:formatDate value="${taskMainExecDetialRequest.beginTaskEnd}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                        onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> -
                    <input name="endTaskEnd" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
                        value="<fmt:formatDate value="${taskMainExecDetialRequest.endTaskEnd}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                        onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
                </li>
                <li><label>操作人：</label>
                    <sys:treeselect id="taskOperator" name="taskOperator.id" value="${taskMainExecDetialRequest.taskOperator.id}" labelName="taskOperator.name" labelValue="${taskMainExecDetialRequest.taskOperator.name}"
                        title="用户" url="/sys/office/treeData?type=3" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
                </li>
                <li><label>任务类型：</label>
                    <form:select path="taskType" class="input-medium">
                        <form:option value="" label=""/>
                        <form:options items="${fns:getDictList('DEVCHK_PERIOD')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                    </form:select>
                </li>
                <li><label>部门：</label>
                    <sys:treeselect id="sysOffice" name="sysOffice.id" value="${taskMainExecDetialRequest.sysOffice.id}" labelName="sysOffice.name" labelValue="${taskMainExecDetialRequest.sysOffice.name}"
                        title="部门" url="/sys/office/treeData?type=2" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
                </li>
                <li><label>任务状态：</label>
                    <form:select path="taskStatus" class="input-medium">
                        <form:option value="" label=""/>
                        <form:options items="${fns:getDictList('TASK_MAIN_STATUS')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                    </form:select>
                    <input id="taskMainId" type="hidden" name="taskMainId" value="${taskMainId}" />
                    <input type="hidden" name="flag" value="${flag}" />
                </li>
                <li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>--%>
			<li class="btns"><a href="javascript: void(0);" class="btn btn-primary" onclick="exportData()">导出</a></li>

			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<%--<th style="width:60px">任务标题</th>--%>
				<th style="width:100px">设备名称</th>
				<th style="width:60px">任务执行人</th>
				<th style="width:60px">任务类型</th>
				<th style="width:60px">车站值班人员</th>
				<th style="width:60px">跟班人员</th>
				<th style="width:60px">网调室人员</th>



				<th style="width:60px">检修周期</th>
				<th style="width:60px">签到时间</th>
				<th style="width:60px">实际时间</th>
				<th style="width:60px">任务状态</th>
				<th style="width:100px">检修内容</th>
				<th style="width:100px">检修标准</th>
				<th style="width:100px">检修方法</th>
				<th style="width:60px">是否正常</th>
				<th style="width:60px">备注</th>
				<th style="width:100px">测量值</th>
				<th style="width:100px">操作</th>
				<%--<shiro:hasPermission name="devmng:taskMain:edit"><th>操作</th></shiro:hasPermission>--%>
			</tr>
		</thead>
		<tbody>
			<c:set var="compare" value=""/>
			<c:set var="count" value="0" />
		<c:forEach items="${page.list}" var="taskMain">
			<c:if test="${taskMain.taskStatus == 'CLOSE'}">
				<c:set var="color"  value="id = bc-close"/>
			</c:if>
			<c:if test="${taskMain.taskStatus == 'OPEN'}">
				<c:set var="color"  value="id = bc-open"/>
			</c:if>
			<c:if test="${taskMain.taskStatus == 'PROCESSING'}">
				<c:set var="color"  value="id = bc-processing"/>
			</c:if>

			<c:set var="count" value="0" />

			<c:if test="${!compare.equals(taskMain.deviceMainId)}">
				<c:forEach items="${page.list}" var="taskDevchk">
					<c:if test="${taskMain.deviceMainId.equals(taskDevchk.deviceMainId)}">
					<c:set var="count" value="${count+1}"/>
					</c:if>
				</c:forEach>
			</c:if>

			<c:set var="compare" value="${taskMain.deviceMainId}"/>
			<tr <c:out value="${color}"/>>
				<c:if test="${count != 0}">
					<td rowspan="<c:out value="${count}"/>">
							${taskMain.deviceName}
					</td>
					<td rowspan="<c:out value="${count}"/>">
						${taskMain.taskOperator.name}
					</td>
					<td rowspan="<c:out value="${count}"/>">

							${ fns:getDictLabel (taskMain.taskType, 'DEVCHK_PERIOD', '')}
					</td>

					<td rowspan="<c:out value="${count}"/>">
							<%--<fmt:formatDate value="${taskMain.startDate}" pattern="yyyy-MM-dd HH:mm:ss"/>--%>
							${taskMain.stationDutyPerson}
					</td>

					<td rowspan="<c:out value="${count}"/>">
							<%--<fmt:formatDate value="${taskMain.closeDate}" pattern="yyyy-MM-dd HH:mm:ss"/>--%>
							${taskMain.stationAttendant}
					</td>

					<td rowspan="<c:out value="${count}"/>">
							<%--<fmt:formatDate value="${taskMain.taskStart}" pattern="yyyy-MM-dd HH:mm:ss"/>--%>
							${taskMain.netDispatcher}
					</td>

					<td rowspan="<c:out value="${count}"/>">
							${ fns:getDictLabel (taskMain.checkPeriod, 'DEVCHK_PERIOD', '')}
					</td>
				</c:if>

				<td>
					<fmt:formatDate value="${taskMain.startDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>

				<td>
					<fmt:formatDate value="${taskMain.recordUpdateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>

				<td>
						${ fns:getDictLabel (taskMain.taskStatus, 'TASK_MAIN_STATUS', '')}
				</td>

				<td>
						${taskMain.checkContent}
				</td>

				<td>
						${taskMain.checkStd}
				</td>

				<td>
						${taskMain.checkMethod}
				</td>

				<td>
						${taskMain.normalDesc}
				</td>

				<td>
						${taskMain.remarks}
				</td>

				<td>
						${taskMain.meatureDesc}
				</td>

				<td>
					<c:choose>
						<c:when test="${taskMain.flagUrl.equals('Y')}">
							<a href="javascript:void(0)"
							   onclick='showDetail("${taskMain.taskMainId}", "${taskMain.deviceMainId}", "${taskMain.devchkItemId}");'>
								查看图片
							</a>
						</c:when>
						<c:otherwise>
							无
						</c:otherwise>
					</c:choose>
				</td>
				<%--<shiro:hasPermission name="devmng:taskMain:edit"><td>--%>
					<%--<a href="${ctx}/devmng/taskMain/detail?id=${taskMain.id}">详情</a>--%>
    				<%--<a href="${ctx}/devmng/taskMain/generate?id=${taskMain.id}">修改</a>--%>
					<%--<a href="${ctx}/devmng/taskMain/delete?id=${taskMain.id}" onclick="return confirmx('确认要删除该任务吗？', this.href)">删除</a>--%>
				<%--</td></shiro:hasPermission>--%>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>